<?php

// ##############################################################################||
// #                                                                 
// #   MySmartBB Version 1.7.0	                                      
// #   http://www.MySmartBB.com                                      
// #   Copyright (c) 2008 by MySmartBB team                           
// #   license http://opensource.org/licenses/gpl-license.php GNU Public License
// #                                                             
// #   filename : memberlist.php                                           
// #   show the member list                             
// #                                                                  
// ##############################################################################||


// ** General definitions **

     define('NOT_IN_INDEX',0);
     include('common.php');
     include('includes/pager.php');

     $SF->html_title_page('قائمة الأعضاء - (Powered By MySmartBB Universal)');
     if ($groupper_row['memberlist_allow'] == 0)
     {
         $SF->error('<br />المعذرة، لا يمكنك استخدام قائمة الأعضاء');
     }

     if ($_GET['show'] == 1)
     {
         if (!isset($_GET['page']) OR $_GET['page'] < 1)
         {
             $_GET['page'] = 1;
         }

         $page  = intval($_GET['page']);
         $start = ($info_row['perpage'] * ($page-1));

         $RP = new Pager($page);

         if (empty($_GET['order']))
         {
             $member_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "member ORDER BY id DESC LIMIT $start," . $info_row['perpage'] ."");
             $Smarty->assign('dont_print_SC',1);
         }
         
         /** 1.5.0 Patch 2 **/
         if (($_GET['order'] <= 1) or ($_GET['order'] > 3))
         /** **/
         {
             if ($_GET['order_type'] == 'DESC')
             {
                 $member_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "member ORDER BY posts DESC LIMIT $start," . $info_row['perpage'] ."");
             }
             else
             {
                 $member_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "member ORDER BY posts ASC LIMIT $start," . $info_row['perpage'] ."");
             }
         }
         elseif ($_GET['order'] == 2)
         {
             if ($_GET['order_type'] == 'DESC')
             {
                 $member_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "member ORDER BY id DESC LIMIT $start," . $info_row['perpage'] ."");
             }
             else
             {
                 $member_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "member ORDER BY id ASC LIMIT $start," . $info_row['perpage'] ."");
             }
         }

         if ($_GET['order'] == 3)
         {
             if ($_GET['order_type'] == 'DESC')
             {
                 $member_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "member ORDER BY visitor DESC LIMIT $start," . $info_row['perpage'] ."");
             }
             else
             {
                 $member_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "member ORDER BY visitor ASC LIMIT $start," . $info_row['perpage'] ."");
             }
         }

         $memberlist_row = array();
         while ($memberrow = $DB->sql_fetch_array($member_query))
         {
             $memberlist_row[] = $memberrow;
             $Smarty->assign('memberlist_row',$memberlist_row);
         }

         $RP->SetPagerN($info_row['perpage'],$DB->sql_num_rows($DB->sql_query("SELECT * FROM " . $db_prefix . "member")));

         $Smarty->assign('print_page',$RP->PageNum('show=1&order=' . $_GET['order'] . '&order_type=' . $_GET['order_type'] . ''));

         $url = "{$REQUEST_URI}";
         $url_array = explode('ASC',$url);

         if (count($url_array) == 2)
         {
             $url        = str_replace('ASC','DESC',$url);
             $type_print = "تصاعدي";
         }
         elseif (count($url_array) == 1)
         {
             $url        = str_replace('DESC','ASC',$url);
             $type_print = "تنازلي";
         }

         $Smarty->assign('type_print',$type_print);
         $Smarty->assign('url',$url);
		 
         $Smarty->assign('path_bar','قائمة الأعضاء');
         $Smarty->display('path-bar.tpl');
		 
         $Smarty->display('memberlist.tpl');

         $SF->FastMove();

         $Smarty->display('footer.tpl');
     }

		if ($_GET['show'] == 2)
			{
				$membersearch	= $_POST['member'];

				if (!empty($membersearch))
				{
					$datau = $DB->sql_query("SELECT * FROM " . $db_prefix . "member WHERE username LIKE '%" .$membersearch . "%'");

         			$datau_num = $DB->sql_num_rows($datau);
					
         				if ($datau_num == 0)
         					{
								$SF->error('عُذراً ولكن لايوجد نتائج , حاول البحث بصيغة مختلفة');
         					}

						while($row = mysql_fetch_array($datau))
						{
             				$membersearch_row[] = $row;
             				$Smarty->assign_by_ref('membersearch_row',$membersearch_row);
             				$Smarty->assign('membersearch_row',$membersearch_row);
						}
				}
				else
				{
					$SF->error("المعذرة، الرجاء ادخال كلمة للبحث عنها<br />");
					$Smarty->display('footer.tpl');
					exit;
				}

        			$Smarty->display('member_search_result.tpl');

         			$SF->FastMove();

         			$Smarty->display('footer.tpl');
			}


?>